package com.pkk.log.web.configure;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

/**
 * Freemarker配置
 */
@Configuration
public class FreemarkerConfig {

  /**
   * @Description: 配置freeMarker
   * @Param: []
   * @return: org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
   * @Author: peikunkun
   * @Date: 2019/7/13 0013 下午 8:13
   */
  @Bean
  public FreeMarkerConfigurer freeMarkerConfigurer() {
    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
    freeMarkerConfigurer.setTemplateLoaderPath("classpath:/templates");
    freeMarkerConfigurer.setDefaultEncoding("utf-8");
    // 加上这句后，可以在页面上使用shiro标签
    Map<String, Object> variables = new HashMap<>(1);
    variables.put("shiro", new ShiroTag());
    freeMarkerConfigurer.setFreemarkerVariables(variables);

    Properties settings = new Properties();
    settings.setProperty("number_format", "0.##");
    freeMarkerConfigurer.setFreemarkerSettings(settings);
    return freeMarkerConfigurer;
  }

}
